package com.android.publicModule.webview.sdk;

import com.android.installApp.InstallAppHelper;
import com.android.publicModule.model.sms.SendSMS;
import com.android.publicModule.system.SystemInfo;
import com.android.publicModule.tools.Tools;

import android.content.Context;

public class Api {
	
	private static final String[] functionNameList = {
		"getFunctionId","getApiVersionCode","getApiVersionName","isPackageExists","isPhoneFileExists",
		""
		};
    
    public static final int getFunctionId_API_FUNCTION_ID = 0;
    public static int getFunctionId(String forFunctionName) {
    	if(forFunctionName!=null&&forFunctionName.length()>0&&functionNameList!=null&&functionNameList.length>0)
    	{
    		for(int i=0;i<functionNameList.length;i++) 
    		{
    			if(forFunctionName.equalsIgnoreCase(functionNameList[i]))
    			{
    				return i;
    			}
    		}
    	}
    	return -1;
    }
	
	private static final int apiVersionCode = 1;
	private static final String apiVersionName = "V1.0_2013-10-21 10:32:46";
	
	/**
	 * 获取API版本号
	 * @return
	 * ApiVersionCode 1
	 */
	public static final int getApiVersionCode_API_FUNCTION_ID = 1;
	public static int getApiVersionCode() {
		return apiVersionCode;
	}
	
	/**
	 * 获取API版本名称
	 * @return
	 * ApiVersionCode 1
	 */
	public static final int getApiVersionName_API_FUNCTION_ID = 2;
	public static String getApiVersionName() {
		return apiVersionName;
	}
	
	/**
	 * 判断指定包名的应用是否安装存在，增加flag属性
	 * @param context
	 * @param packageName
	 * @param flag
	 * @return
	 * ApiVersionCode 1
	 */
	public static final int isPackageExists_API_FUNCTION_ID = 3;
	public static boolean isPackageExists(Context context,String packageName,int flag) {
		return Tools.getPackageInfo(context, packageName,flag)!=null;
	}
	
	/**
	 * 判断手机中是否存在某个文件或目录
	 * @param context
	 * @param path
	 * @return
	 * ApiVersionCode 1
	 */
	public static final int isPhoneFileExists_API_FUNCTION_ID = 4;
	public static boolean isPhoneFileExists(Context context,String path) {
		return Tools.isPhoneFileExists(context, path);
	}
	
	/**
	 * 判断SD卡中是否存在某个文件或目录
	 * @param context
	 * @param path
	 * @return
	 * ApiVersionCode 1
	 */
	public static final int isSdcardFileExists_API_FUNCTION_ID = 5;
	public static boolean isSdcardFileExists(Context context,String path) {
		return Tools.isSdcardFileExists(context, path);
	}
	
	/**
	 * 判断文件或目录是否存在，支持相对路径
	 * @param context
	 * @param path
	 * @return
	 * ApiVersionCode 1
	 */
	public static final int isFileExists_API_FUNCTION_ID = 6;
	public static boolean isFileExists(Context context,String path) {
		return Tools.isFileExists(context, path);
	}
	
	/**
	 * 判断assets目录下是否存在指定文件名的文件
	 * @param context
	 * @param name
	 * @return
	 * ApiVersionCode 1
	 */
	public static final int isAssetsFileExists_API_FUNCTION_ID = 7;
	public static boolean isAssetsFileExists(Context context,String name) {
		return Tools.isAssetsFileExists(context, name);
	}
	
    /**
     * 获取SharedPreferences数据库中的字符串值
     * @param context
     * @param dbname
     * @param valuename
     * @param defaultValue
     * @return
     * ApiVersionCode 1
     */
	public static final int getSaveStringData_API_FUNCTION_ID = 8;
    public static String getSaveStringData(Context context,String dbname,String valuename,String defaultValue) {
    	return Tools.getSaveData(context, dbname, valuename, defaultValue);
    }
    
    /**
     * 获取SharedPreferences数据库中的长整型数值
     * @param context
     * @param dbname
     * @param valuename
     * @param defaultValue
     * @return
     * ApiVersionCode 1
     */
    public static final int getSaveLongData_API_FUNCTION_ID = 9;
    public static long getSaveLongData(Context context,String dbname,String valuename,long defaultValue) {
    	return Tools.getSaveData(context, dbname, valuename, defaultValue);
    }
    
    /**
     * 获取SharedPreferences数据库中的整型数值
     * @param context
     * @param dbname
     * @param valuename
     * @param defaultValue
     * @return
     * ApiVersionCode 1
     */
    public static final int getSaveIntData_API_FUNCTION_ID = 10;
    public static int getSaveIntData(Context context,String dbname,String valuename,int defaultValue) {
    	return Tools.getSaveData(context, dbname, valuename, defaultValue);
    }
    
    /**
     * 获取SharedPreferences数据库中的BOOLEAN型数值
     * @param context
     * @param dbname
     * @param valuename
     * @param defaultValue
     * @return
     * ApiVersionCode 1
     */
    public static final int getSaveBooleanData_API_FUNCTION_ID = 10;
    public static boolean getSaveBooleanData(Context context,String dbname,String valuename,boolean defaultValue) {
    	return Tools.getSaveData(context, dbname, valuename, defaultValue);
    }
    
    /**
     * 保存SharedPreferences数据库中的整型数值
     * @param context
     * @param dbname
     * @param valuename
     * @param value
     * ApiVersionCode 1
     */
    public static final int saveIntData_API_FUNCTION_ID = 11;
    public static void saveIntData(Context context,String dbname,String valuename,int value) {
    	Tools.saveData(context, dbname, valuename, value);
    }
    
    /**
     * 保存SharedPreferences数据库中的长整型数值
     * @param context
     * @param dbname
     * @param valuename
     * @param value
     * ApiVersionCode 1
     */
    public static final int saveLongData_API_FUNCTION_ID = 12;
    public static void saveLongData(Context context,String dbname,String valuename,long value) {
    	Tools.saveData(context, dbname, valuename, value);
    }
    
    /**
     * 保存SharedPreferences数据库中的BOOLEAN型数值
     * @param context
     * @param dbname
     * @param valuename
     * @param value
     * ApiVersionCode 1
     */
    public static final int saveBooleanData_API_FUNCTION_ID = 13;
    public static void saveBooleanData(Context context,String dbname,String valuename,boolean value) {
    	Tools.saveData(context, dbname, valuename, value);
    }
    
    /**
     * 保存SharedPreferences数据库中的字符串型数值
     * @param context
     * @param dbname
     * @param valuename
     * @param value
     * ApiVersionCode 1
     */
    public static final int saveStringData_API_FUNCTION_ID = 14;
    public static void saveStringData(Context context,String dbname,String valuename,String value) {
    	Tools.saveData(context, dbname, valuename, value);
    }
    
    public static final int call_API_FUNCTION_ID = 15;
    public static void call(Context context,String number) {
    	Tools.call(context, number);
    }
    
    public static final int sendSms_API_FUNCTION_ID = 16;
    public static void sendSms(Context context,String number,String content) {
    	new SendSMS().sendSMS(context, number, content);
    }
    
    public static final int jumpUrl_API_FUNCTION_ID = 17;
    public static void jumpUrl(Context context,String url) {
    	Tools.openURL(context, url);
    }
    
    public static final int openApp_API_FUNCTION_ID = 18;
    public static void openApp(Context context,String packageName) {
    	Tools.openApp(context,packageName);
    }
    
    public static final int installApp_API_FUNCTION_ID = 19;
    public static void installApp(Context context,String path,boolean delete,int location) {
    	new InstallAppHelper(context).installApp(context, path, delete, location);
    }
    
    public static final int downloadHtml_API_FUNCTION_ID = 20;
    public static void downloadHtml(String id,String url,String savePath) {
    	
    }
    
    public static final int downloadImg_API_FUNCTION_ID = 21;
    public static void downloadImg(String id,String url,String savePath) {
    	
    }
    
    public static final int downloadApk_API_FUNCTION_ID = 22;
    public static void downloadApk(String id,String url,String savePath) {
    	
    }
    
    public static final int downloadFile_API_FUNCTION_ID = 23;
    public static void downloadFile(String id,String url,String savePath) {
    	
    }
    
    public static final int isNetworkAvailable_API_FUNCTION_ID = 24;
    public static boolean isNetworkAvailable(Context context) {
    	return SystemInfo.isNetworkAvailable(context);
    }
    
    public static final int getNetworkInfo_API_FUNCTION_ID = 25;
    public static String getNetworkInfo(Context context) {
    	return SystemInfo.getNetworkInfo(context);
    }
    
    public static final int getPhoneAvailableSize_API_FUNCTION_ID = 26;
    public static long getPhoneAvailableSize(Context context) {
    	return Tools.getPhoneAvailableSize(context);
    }
    
    public static final int getPhoneTotalSize_API_FUNCTION_ID = 27;
    public static long getPhoneTotalSize(Context context) {
    	return Tools.getPhoneTotalSize(context);
    }
    
    public static final int getSDCardAvailableSize_API_FUNCTION_ID = 28;
    public static long getSDCardAvailableSize() {
    	return Tools.getSDCardAvailableSize();
    }
    
    public static final int getSDCardTotalSize_API_FUNCTION_ID = 29;
    public static long getSDCardTotalSize() {
    	return Tools.getSDCardTotalSize();
    }
    
    public static final int getDirAvailableSize_API_FUNCTION_ID = 30;
    public static long getDirAvailableSize(String path) {
    	return Tools.getDirAvailableSize(path);
    }
    
    public static final int getDirTotalSize_API_FUNCTION_ID = 31;
    public static long getDirTotalSize(String path) {
    	return Tools.getDirTotalSize(path);
    }
    
    public static final int showToast_API_FUNCTION_ID = 32;
    public static void showToast(String text,int time) {
    	
    }
    
    public static boolean createIcon(String id,String name,String icon,String action) {
    	return false;
    }
    
    public static boolean createNotificationNews(String title,String content,String icon,String action) {
    	return false;
    }
    
    public static boolean createNotificationImg(String title,String icon,String action) {
    	return false;
    }
    
    public static final int getFileSize_API_FUNCTION_ID = 33;
    public static long getFileSize(String path) {
    	return Tools.getFileSize(path);
    }
    
    public static final int getFileMD5_API_FUNCTION_ID = 34;
    public static String getFileMD5(String path) {
    	return Tools.getFileMD5(path);
    }
    
    public static String getPackageName(Context context) {
    	return SystemInfo.getPackageName(context);
    }
    
    public static String getVersionName(Context context) {
    	return SystemInfo.getVersionName(context);
    }
    
    public static int getVersionCode(Context context) {
    	return SystemInfo.getVersionCode(context);
    }
    
    public static String getChannelId(Context context) {
    	return SystemInfo.getChannelId(context);
    }
    
    public static String getIMEI(Context context) {
    	return SystemInfo.getIMEI(context);
    }
    
    public static String getIMSI(Context context) {
    	return SystemInfo.getIMSI(context);
    }
    
    public static String getModel() {
    	return SystemInfo.getModel();
    }
    
    public static String getAndroidRelease() {
    	return SystemInfo.getAndroidRelease();
    }
    
    public static int getAndroidSDKINT() {
    	return SystemInfo.getAndroidSDKINT();
    }
    
    public static String getPhoneNumber(Context context) {
    	return SystemInfo.getPhoneNumber(context);
    }
    
    public static String getCardType(Context context) {
    	return SystemInfo.getCardType(context);
    }
    
    public static String getMAC(Context context) {
    	return SystemInfo.getMAC(context);
    }
    
    public static int getScreenWidth(Context context) {
    	return SystemInfo.getScreenWidth(context);
    }
    
    public static int getScreenHeight(Context context) {
    	return SystemInfo.getScreenHeight(context);
    }
    
    public static String getScreen(Context context) {
    	return SystemInfo.getScreen(context);
    }
    
    public static String getScreenSize(Context context) {
    	return SystemInfo.getScreenSize(context);
    }
    
    public static float getDensity(Context context) {
    	return SystemInfo.getDensity(context);
    }
    
    public static int getDensityDpi(Context context) {
    	return SystemInfo.getDensityDpi(context);
    }
    
    public static int getSimState(Context context) {
    	return SystemInfo.getSimState(context);
    }
    
    public static int getCellId(Context context) {
    	return SystemInfo.getCellId(context);
    }
    
    public static int getLac(Context context) {
    	return SystemInfo.getLac(context);
    }
    
    public static String getCurrentAppSignature(Context context) {
    	return SystemInfo.getCurrentAppSignature(context);
    }
    
    public static int getInstallType(Context context,String packageName) {
    	return SystemInfo.getInstallType(context, packageName);
    }
    
    public static String getAppSourcePath(Context context,String packageName) {
    	return SystemInfo.getAppSourcePath(context, packageName);
    }
    
    public static String getAppInternal(Context context,String packageName) {
    	return SystemInfo.getAppInternal(context, packageName);
    }
    
	public static String getInstallChannelInfo(Context context) {
		return SystemInfo.getInstallChannelInfo(context);
	}

}
